-
- Checks repository version and handles upgrades too.
-}
-ensureInitialized :: Annex ()
-ensureInitialized = getInitializedVersion >>= maybe needsinit checkUpgrade
+ensureInitialized :: Annex [Remote] -> Annex ()
+ensureInitialized remotelist = getInitializedVersion >>= maybe needsinit checkUpgrade
where
needsinit = ifM autoInitializeAllowed
( do
Right () -> noop
Left e -> giveup $ show e ++ "\n" ++
"git-annex: automatic initialization failed due to above problems"
- autoEnableSpecialRemotes
+ autoEnableSpecialRemotes remotelist
, giveup "First run: git-annex init"
)
-
- Checks repository version and handles upgrades too.
-}
-autoInitialize :: Annex ()
-autoInitialize = getInitializedVersion >>= maybe needsinit checkUpgrade
+autoInitialize :: Annex [Remote] -> Annex ()
+autoInitialize remotelist = getInitializedVersion >>= maybe needsinit checkUpgrade
where
needsinit =
whenM (initializeAllowed <&&> autoInitializeAllowed) $ do
initialize True Nothing Nothing
- autoEnableSpecialRemotes
+ autoEnableSpecialRemotes remotelist
{- Checks if a repository is initialized. Does not check version for ugrade. -}
isInitialized :: Annex Bool
{- Try to enable any special remotes that are configured to do so.
-
- The enabling is done in a child process to avoid it using stdio.
+ -
+ - The remotelist should be Remote.List.remoteList, which cannot
+ - be imported here due to a dependency loop.
-}
-autoEnableSpecialRemotes :: Annex ()
-autoEnableSpecialRemotes = do
+autoEnableSpecialRemotes :: Annex [Remote] -> Annex ()
+autoEnableSpecialRemotes remotelist = do
+ -- Get all existing git remotes to probe for their uuid here,
+ -- so it is not done inside the child process. Doing it in there
+ -- could result in password prompts for http credentials,
+ -- which would then not end up cached in this process's state.
+ _ <- remotelist
rp <- fromRawFilePath <$> fromRepo Git.repoPath
withNullHandle $ \nullh -> gitAnnexChildProcess "init"
[ Param "--autoenable" ]
import Types.Transfer
import Types.ActionItem
import Types.WorkerPool as ReExported
+import Remote.List
{- Generates a normal Command -}
command :: String -> CommandSection -> String -> CmdParamsDesc -> (CmdParamsDesc -> CommandParser) -> Command
commonChecks = [repoExists]
repoExists :: CommandCheck
-repoExists = CommandCheck 0 ensureInitialized
+repoExists = CommandCheck 0 (ensureInitialized remoteList)
notBareRepo :: Command -> Command
notBareRepo = addCheck checkNotBareRepo
readlocalannexconfig = do
let check = do
Annex.BranchState.disableUpdate
- catchNonAsync autoInitialize $ \e ->
+ catchNonAsync (autoInitialize (pure [])) $ \e ->
warning $ "remote " ++ Git.repoDescribe r ++
":" ++ show e
Annex.getState Annex.repo
s <- Annex.new r
Annex.eval s $ do
Annex.BranchState.disableUpdate
- ensureInitialized
+ ensureInitialized (pure [])
a `finally` stopCoProcesses
data LocalRemoteAnnex = LocalRemoteAnnex Git.Repo (MVar [(Annex.AnnexState, Annex.AnnexRead)])
[] -> do
liftIO $ putMVar mv []
v <- newLocal repo
- go (v, ensureInitialized >> a)
+ go (v, ensureInitialized (pure []) >> a)
(v:rest) -> do
liftIO $ putMVar mv rest
go (v, a)
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 4"""
+ date="2022-09-09T18:39:06Z"
+ content="""
+Fixed the autoinit case.
+
+I'm going to close this as done, despite the cases mentioned above where
+subprocesses might redundantly prompt for the credentials.
+
+Another reason
+to not worry about those is that `git-annex sync` runs `git fetch` and `git
+push` (more than once), so there will be several password prompts there.
+So when git-annex runs a git-annex subprocess, it follows it's just as ok
+for it to do its own password prompts as it is for a git subprocess to do
+so. The solution to either is certianly to enable git's credential cache.
+So the scope of this todo has to be limited to prompting done by a single
+git-annex process.
+"""]]